/*
题目描述
建立一个链表，每个节点包括：学号、姓名、性别、年龄。输入一个年龄，如果链表中的节点所包含的年龄等于这个年龄，则将所有符合要求的节点删去。

输入
第一行有一个整数n，表示链表中的节点个数。保证n不超过100。
之后的n行每行有4个用空格隔开的部分，分别为学号（正整数）、姓名（长度不超过20且不包含空格的字符串）、性别（字符m或f）、年龄（正整数）。
最后一行有一个整数age，表示需要删除的节点年龄。

输出
首先输出链表最终剩下的节点个数k。
在接下来的k行，每行输出4个用空格隔开的部分，分别为学号、姓名、性别和年龄，与输入格式相同。
请注意行尾输出换行。
*/
#include <stdio.h>
#include <stdlib.h>
#include <string.h>

typedef struct student
{
    int id;
    char name[21];
    char gender;
    int age;
    struct student *next;
} Student;

Student *createNode(int id, char name[21], char gender, int age)
{
    Student *newNode = (struct student *)malloc(sizeof(struct student));
    newNode->id = id;
    strcpy(newNode->name, name);
    newNode->gender = gender;
    newNode->age = age;
    newNode->next = NULL;
    return newNode;
}

Student *insertNode(Student *List, int id, char name[21], char gender, int age)
{
    Student *newNode = createNode(id, name, gender, age);
    Student *head = List;
    Student *current = List;
    if (id < head->id)
    {
        newNode->next = head;
        return newNode;
    }
    while (current->next != NULL)
    {
        if (current->next->id > id)
        {
            newNode->next = current->next;
            current->next = newNode;
            return head;
        }
        else
        {
            current = current->next;
        }
    }
    current->next = newNode;
    return head;
}

Student *deleteNode(Student *List, int age)
{
    Student *head = List;
    Student *current = List;
    while (current != NULL)
    {
        // 头结点
        if (head->age == age)
        {
            Student *next = head->next;
            free(head);
            head = next;
        }
        if (current->next != NULL && current->next->age == age)
        {
            Student *next = current->next;
            current->next = current->next->next;
            free(next);
        }
        else
        {
            current = current->next;
        }
    }
    return head;
}

Student *buildList(int n)
{
    int id, age;
    char name[21], gender;
    scanf("%d %s %c %d", &id, &name, &gender, &age);
    Student *head = createNode(id, name, gender, age);
    for (int i = 1; i < n; i++)
    {
        int newId, newAge;
        char newName[21], newGender;
        scanf("%d %s %c %d", &newId, &newName, &newGender, &newAge);
        head = insertNode(head, newId, newName, newGender, newAge);
    }
    return head;
}

int getListLength(Student *List)
{
    int length = 0;
    Student *current = List;
    while (current != NULL)
    {
        length++;
        current = current->next;
    }
    return length;
}

void printList(Student *List)
{
    Student *head = List;
    Student *current = List;
    while (current != NULL)
    {
        printf("%d %s %c %d\n", current->id, current->name, current->gender, current->age);
        current = current->next;
    }
}

int main()
{
    int k,age;
    scanf("%d", &k);
    Student *list = buildList(k);
    scanf("%d",&age);
    list = deleteNode(list,age);
    printf("%d\n",getListLength(list));
    printList(list);
}